package com.lagou.spi;

import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.*;


/**
 * 1. dubbo通过setter注入, 且只支持setter注入, spring的注解不被支持
 * 2. 支持 ApplicationContextAware 进行获取spring容器里的对象
 */
//@Activate(group = {CommonConstants.PROVIDER})
public class TransportIPFilter implements Filter{
    @Override
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {

        String clientIp = RpcContext.getContext().getAttachment("clientIp");
        String browser = RpcContext.getContext().getAttachment("browser");
        System.out.println(String.format("客户端ip: %s, 客户端类型: %s", clientIp, browser));

        return invoker.invoke(invocation);
    }
}
